package sim.ring.gui.treedata;

public abstract class DataModel {
	
	protected DataModel parent;
	protected int id;
	protected String name;
	protected IChangeListener changeListener = DataModelChangeListener.getInstance();
	
	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
	}

	
	public DataModel getParent() {
		return parent;
	}
	public void setParent(DataModel parent) {
		this.parent = parent;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	public DataModel() { }
	
	public DataModel(String modelName) {
		this.id = 0;
		this.name = modelName;
	}
	
	public abstract void accept(IDataModelVisitor visitor, Object args);
	
	public abstract void add(DataModel model);
	public abstract void remove(DataModel model);
	
	protected void fireAddEvent(Object args) {
		changeListener.add(new ChangeEvent(args));
	}
	
	protected void fireRemoveEvent(Object args) {
		changeListener.remove(new ChangeEvent(args));
	}
	
	public void addChangeListener(IChangeListener listener) {
		this.changeListener = listener;
	}
	
	public void removeChangeListener(IChangeListener listener) {
		if (this.changeListener.equals(listener))
			this.changeListener = DataModelChangeListener.getInstance();
	}

}
